package com.share.alibaba.auser.listener;

import com.share.common.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Set;

/**
 * 监控nacos配置的事件
 */
@Slf4j
@Component
public class EnvironmentChangeEventListener implements ApplicationListener<EnvironmentChangeEvent> {

    @Override
    public void onApplicationEvent(EnvironmentChangeEvent environmentChangeEvent) {
        //对于EnvironmentChangeEvent,主要是监控keys
        Set<String> changeKeys = environmentChangeEvent.getKeys();
        long timestamp = environmentChangeEvent.getTimestamp();
        Date changeDate = new Date(timestamp);

        log.info("nacos配置变更了,changeDate={},changeKeys={}", DateUtil.getDate(changeDate), changeKeys);
    }
}